home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / LiveFastStartServer / Open Transport 1.3 / Includes / CIncludes / OpenTptCommon.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-30  |  4.6 KB  |  181 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        OpenTptCommon.h
  3.  
  4.     Contains:    Equates for Open Transport development needed both by clients
  5.                 and by kernel.
  6.  
  7.     Copyright:    © 1993-1996 by Apple Computer, Inc. and Mentat Inc., all rights reserved.
  8.  
  9.  
  10. */
  11.  
  12. #ifndef __OPENTPTCOMMON__
  13. #define __OPENTPTCOMMON__
  14.  
  15. #ifndef __OPENTRANSPORT__
  16. #include <OpenTransport.h>
  17. #endif
  18.  
  19. #if defined(__MWERKS__) && GENERATING68K
  20. #pragma pointers_in_D0
  21. #endif
  22.  
  23. #if PRAGMA_ALIGN_SUPPORTED
  24. #pragma options align=mac68k
  25. #endif
  26. #if PRAGMA_IMPORT_SUPPORTED
  27. #pragma import on
  28. #endif
  29.  
  30.  
  31. /*******************************************************************************
  32. ** Bitmap functions
  33. **
  34. ** These functions atomically deal with a bitmap that is multiple-bytes long
  35. ********************************************************************************/
  36.  
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40.     //
  41.     // Set the first clear bit in "bitMap", starting with bit "startBit",
  42.     // giving up after "numBits".  Returns the bit # that was set, or
  43.     // a kOTNotFoundErr if there was no clear bit available
  44.     //
  45.     extern OTResult    OTSetFirstClearBit(UInt8* bitMap, size_t startBit, size_t numBits);
  46.     //
  47.     // Standard clear, set and test bit functions
  48.     //
  49.     extern Boolean    OTClearBit(UInt8* bitMap, size_t bitNo);
  50.     extern Boolean    OTSetBit(UInt8* bitMap, size_t bitNo);
  51.     extern Boolean    OTTestBit(UInt8* bitMap, size_t bitNo);
  52.  
  53. #ifdef __cplusplus
  54. }
  55. #endif
  56.  
  57. /*******************************************************************************
  58. ** OTHashList
  59. **
  60. ** This implements a simple, but efficient hash list.  It is not
  61. ** thread-safe.
  62. ********************************************************************************/
  63.  
  64. #ifdef __cplusplus
  65. extern "C" {
  66. #endif
  67.  
  68.     typedef struct OTHashList    OTHashList;
  69.  
  70.     typedef UInt32 (*OTHashProcPtr)(OTLink* linkToHash);
  71.     typedef Boolean (*OTHashSearchProcPtr)(const void* ref, OTLink* linkToCheck);
  72.  
  73.     //
  74.     // Return the number of bytes of memory needed to create a hash list
  75.     // of at least "numEntries" entries.
  76.     //
  77.     extern size_t        OTCalculateHashListMemoryNeeds(size_t numEntries);
  78.     //
  79.     // Create an OTHashList from "memory".  Return an error if it
  80.     // couldn't be done.
  81.     //
  82.     extern OTResult        OTInitHashList(void* memory, size_t numBytes, OTHashProcPtr);
  83.     extern void            OTAddToHashList(OTHashList*, OTLink*);
  84.     extern Boolean        OTRemoveLinkFromHashList(OTHashList*, OTLink*);
  85.     extern Boolean        OTIsInHashList(OTHashList*, OTLink*);
  86.     extern OTLink*        OTFindInHashList(OTHashList*, OTHashSearchProcPtr proc,
  87.                                          const void* refPtr, UInt32 hashValue);
  88.     extern OTLink*        OTRemoveFromHashList(OTHashList*, OTHashSearchProcPtr proc,
  89.                                              const void* refPtr, UInt32 hashValue);
  90.  
  91.     struct OTHashList
  92.     {
  93.         OTHashProcPtr        fHashProc;
  94.         size_t                fHashTableSize;
  95.         OTLink**            fHashBuckets;
  96.  
  97. #ifdef __cplusplus
  98.             void        Add(OTLink* toAdd)
  99.                             { OTAddToHashList(this, toAdd); }
  100.                             
  101.             Boolean        RemoveLink(OTLink* toRemove)
  102.                             { return OTRemoveLinkFromHashList(this, toRemove); }
  103.                             
  104.             OTLink*        Remove(OTHashSearchProcPtr proc,
  105.                                const void* refPtr, UInt32 hashValue)
  106.                             { return OTRemoveFromHashList(this, proc, refPtr, hashValue); }
  107.                             
  108.             Boolean        IsInList(OTLink* toFind)
  109.                             { return OTIsInHashList(this, toFind); }
  110.                             
  111.             OTLink*        FindLink(OTHashSearchProcPtr proc, const void* refPtr,
  112.                                  UInt32 hash)
  113.                             {    return OTFindInHashList(this, proc, refPtr, hash); }
  114. #endif
  115.     };
  116.  
  117. #ifdef __cplusplus
  118. }
  119. #endif
  120.  
  121. /*******************************************************************************
  122. ** Random functions
  123. ** 
  124. ** These implement a very simple random number generator
  125. ********************************************************************************/
  126.  
  127. #ifdef __cplusplus
  128. extern "C" {
  129. #endif
  130.  
  131.     extern UInt32    OTGetRandomSeed();
  132.     extern UInt32    OTGetRandomNumber(UInt32* seed, UInt32 lo, UInt32 hi);
  133.  
  134. #ifdef __cplusplus
  135. }
  136. #endif
  137.  
  138. /*******************************************************************************
  139. ** A simple gating mechanism to singly thread processing of requests.
  140. **
  141. ** Remember - this structure must be on a 4-byte boundary.
  142. ********************************************************************************/
  143.  
  144. typedef Boolean    (*OTGateProcPtr)(OTLink*);
  145.  
  146. struct OTGate
  147. {
  148.     OTLIFO            fLIFO;
  149.     OTList            fList;
  150.     OTGateProcPtr    fProc;
  151.     SInt32            fNumQueued;
  152.     SInt32            fInside;
  153. };
  154.  
  155. typedef struct OTGate    OTGate;
  156.  
  157. #ifdef __cplusplus
  158. extern "C" {
  159. #endif
  160.  
  161. extern void        OTInitGate(OTGate*, OTGateProcPtr proc);
  162. extern Boolean    OTEnterGate(OTGate*, OTLink*);
  163. extern Boolean    OTLeaveGate(OTGate*);
  164.  
  165. #ifdef __cplusplus
  166. }
  167. #endif
  168.  
  169. #if defined(__MWERKS__) && GENERATING68K
  170. #pragma pointers_in_A0
  171. #endif
  172.  
  173. #if PRAGMA_ALIGN_SUPPORTED
  174. #pragma options align=reset
  175. #endif
  176. #if PRAGMA_IMPORT_SUPPORTED
  177. #pragma import off
  178. #endif
  179.  
  180. #endif
  181.